/**
 * 发起登录请求
 * @param {string} name - 用户名
 * @param {string} password - 用户密码
 * @returns {Promise<object>} 登录请求的响应结果
 */
export const loginApi = async (name, password) => {
  try {
    const response = await fetch('/api/user/login', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ name, password })
    });

    if (!response.ok) {
      const errorData = await response.json();
      throw new Error(errorData.message || `HTTP error! status: ${response.status}`);
    }

    return response.json();
  } catch (error) {
    console.error('Login API error:', error);
    throw error;
  }
};